package com.yb.domain.goods;

// default package

import java.util.Date;

import com.yb.base.annotation.Column;
import com.yb.base.annotation.Table;
import com.yb.base.entity.BaseEntity;
import com.yb.bussiness.goods.CategoryMessageService;
import com.yb.bussiness.goods.CategoryMessageServiceImpl;
import com.yb.bussiness.goods.GoodsService;
import com.yb.bussiness.goods.GoodsServiceImpl;
import com.yb.util.comm.DateTimeUtil;

/**
 * TgGoods entity.
 * 
 * @author MyEclipse Persistence Tools
 */
@Table("t_g_goods")
public class TgGoods extends BaseEntity implements java.io.Serializable {

	// Fields
    @Column(name = "reject")
	private static CategoryMessageService service;
	static{
		service = new CategoryMessageServiceImpl();
	}
	
	private String name;
	private String code;
	private String imgSrc;
	private String bigImg;
	private Integer joinCount;
	private Double price;
	private Double upprice;
	private String content;
	private String goodsDesc;
	private Date overTime;
	@Column(name = "reject")
	private String overTimeString;
	private Date createtime;
	@Column(name = "reject")
	private String createtimeString;
	private Long typeId;
	private Long brandId;
	private String announcement;
	private String tel;
	@Column(name = "reject")
	private String firstBrandName;
	@Column(name = "reject")
	private String secondBrandName;
	// Constructors
	@Column(name = "reject")
	private String activeTime;

	@Column(name = "reject")
	private String brandName;

	private Long categoryId;
	private String units;
	private String auditingState;
	private Integer maxCount;
	private Integer weights;
	private String stateMent;

	public String getActivity() {
		Long time1 = overTime.getTime();
		Long time2 = new Date().getTime();
		if (time1 >= time2)
			return "<font color='green'>有效</font>";
		else
			return "<font color='red'>已过期</font>";
	}

	public Integer getWeights() {
		return weights;
	}

	public String getStateMent() {
		if(null == stateMent){
			stateMent = service.getStateMent4Good(categoryId);
		}
		return stateMent;
	}

	public void setStateMent(String stateMent) {
		this.stateMent = stateMent;
	}

	public void setWeights(Integer weights) {
		this.weights = weights;
	}

	public String getUnits() {
		return units;
	}

	public void setUnits(String units) {
		this.units = units;
	}

	public Long getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(Long categoryId) {
		this.categoryId = categoryId;
	}

	public String getShortName() {
		String temp = "";
		if (null != name) {
			temp = name.replaceAll(" ", "").trim();
			if (temp.length() > 5) {
				temp = temp.substring(0, 2) + "…"
						+ temp.substring(temp.length() - 2);
			}
			return temp;
		}
		return this.name.trim();
	}

	public String getActiveTime() {
		if (null == activeTime && null != overTime) {
			Date nowDate = DateTimeUtil.getCurrentDateTime();
			long time = overTime.getTime() - nowDate.getTime();
			long day = (time) / (24 * 60 * 60 * 1000);
			long hour = ((time) % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000);
			long mimute = (time % (60 * 60 * 1000)) / (60 * 1000);
			long second = (time % (60 * 1000)) / 1000;
			activeTime = "剩余：" + (day > 0 ? (day + "天") : "0天")
					+ (hour > 0 ? (hour + "小时") : "0小时")
					+ (mimute > 0 ? (mimute + "分") : "0分")
					+ (second > 0 ? (second + "秒") : "0秒");
		}
		return activeTime;
	}

	public void setActiveTime(String activeTime) {
		this.activeTime = activeTime;
	}

	public String getFirstBrandName() {
		return firstBrandName;
	}

	public void setFirstBrandName(String firstBrandName) {
		this.firstBrandName = firstBrandName;
	}

	public String getSecondBrandName() {
		return secondBrandName;
	}

	public void setSecondBrandName(String secondBrandName) {
		this.secondBrandName = secondBrandName;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getAnnouncement() {
		if(null == announcement){
			announcement = service.getAnnouncement4Good(categoryId);
		}
		return announcement;
	}

	public void setAnnouncement(String announcement) {
		this.announcement = announcement;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getImgSrc() {
		return this.imgSrc;
	}

	public void setImgSrc(String imgSrc) {
		this.imgSrc = imgSrc;
	}

	public Integer getJoinCount() {
		GoodsService goodService = new GoodsServiceImpl();
		joinCount = goodService.findGoodsCount(getId());
		return this.joinCount;
	}

	public void setJoinCount(Integer joinCount) {
		this.joinCount = joinCount;
	}

	public Double getPrice() {
		return price;
	}

	public String getPriceFormat() {
		if (null != price && price % 1 == 0) {
			return price.intValue() + "";
		}
		return price.toString();
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public Double getUpprice() {
		return upprice;
	}

	public String getUppriceFormat() {
		if (null != upprice && upprice % 1 == 0) {
			return upprice.intValue() + "";
		}
		return upprice.toString();
	}

	public void setUpprice(Double upprice) {
		this.upprice = upprice;
	}

	public String getContent() {
		return this.content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getGoodsDesc() {
		return this.goodsDesc;
	}

	public void setGoodsDesc(String goodsDesc) {
		this.goodsDesc = goodsDesc;
	}

	public Date getOverTime() {
		return this.overTime;
	}

	public void setOverTime(Date overTime) {
		this.overTime = overTime;
	}

	public Date getCreatetime() {
		return this.createtime;
	}

	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}

	public Long getTypeId() {
		return typeId;
	}

	public void setTypeId(Long typeId) {
		this.typeId = typeId;
	}

	public Long getBrandId() {
		return brandId;
	}

	public void setBrandId(Long brandId) {
		this.brandId = brandId;
	}

	public String getOverTimeString() {
		return overTimeString;
	}

	public void setOverTimeString(String overTimeString) {
		this.overTimeString = overTimeString;
	}

	public String getCreatetimeString() {
		return createtimeString;
	}

	public void setCreatetimeString(String createtimeString) {
		this.createtimeString = createtimeString;
	}

	public String getAuditingState() {
		return auditingState;
	}

	public void setAuditingState(String auditingState) {
		this.auditingState = auditingState;
	}

	public Integer getMaxCount() {
		return maxCount;
	}

	public void setMaxCount(Integer maxCount) {
		this.maxCount = maxCount;
	}

	public String getBrandName() {
		return brandName;
	}

	public void setBrandName(String brandName) {
		this.brandName = brandName;
	}

	public static void main(String[] args) {
		Double temp = 2.1;
//		System.out.println(temp.intValue());
	}

	public String getBigImg() {
		return bigImg;
	}

	public void setBigImg(String bigImg) {
		this.bigImg = bigImg;
	}
}